home *** CD-ROM | disk | FTP | other *** search
- Path: news.voicenet.com!news
- From: kobak@voicenet.com (Peter Kobak)
- Newsgroups: comp.lang.c++
- Subject: Forward declarations of typedefs
- Date: 29 Feb 1996 18:30:13 GMT
- Organization: Voicenet - Internet Access - (215)674-9290
- Message-ID: <4h4rbl$or7@news.voicenet.com>
- References: <4h2fhp$si8@elaine22.Stanford.EDU>
- Reply-To: kobak@voicenet.com
- NNTP-Posting-Host: ivyland335.voicenet.com
- X-Newsreader: NeoLogic News for OS/2 [version: 4.5 YK Beta]
-
- In message <4h2fhp$si8@elaine22.Stanford.EDU> -
- iburrell@leland.Stanford.EDU (Ian Burrell) writes:
-
- :>I am trying to do a forward declaration of a type defined in another
- :>header so that I can make a class member that is a pointer. However,
- :>if the forward declaration type is later defined as a typedef, I get
- :>lots of errors.
-
- This is an easy mistake to make when moving from C to C++. Despite the
- name, typedef does _not_ define a new type. It's a lot more like a
- #define. When you typedef against a name which was previously declared
- to be a class, you'll always get errors because typedef != class. It's
- like declaring "int a", then later declaring "typedef int a"; they're
- different things.
-
- IMHO, it's best to avoid typedef in C++ altogether, except when you
- genuinely need a symbolic renaming. An example of this is the use of a
- typedef to rename a template instantiation:
-
- typedef CollectionClass<MyThing> MyThingCollection;
-
- In this case, I have _not_ created a new class MyThingCollection. I can
- now refer to the class CollectionClass<MyThing> equivalently as
- MyThingCollection. Again, it's best to think of it like a define:
-
- #define MyThingCollection CollectionClass<MyThing>
-
- ================
- Peter Kobak
- kobak@voicenet.com
-
-
-